import zkUtil from './lib/ZkUtil.js';
import UUID from 'uuid';
import { Router } from 'express';
// import kongUtil from './lib/KongUtil';
var zookeeperConfig = require('./config/zookeeperConfig');
// import { startGetStoreSchedule } from './lib/ScheduleUtil';
// import productManager from './services/ProductManagerService';
import Payload from './models/Payload';
import cron from 'cron';
// import seckillManager from './services/SeckillManagerService';
// import productPreheating from './services/ProductPreheatingService';
import RequestUtil from './lib/RequestUtil';
import redisUtil from './lib/RedisUtil';
// var redisUtil = require('./lib/RedisUtil');
export default () => {
    let api = Router();
    var cronJob = require("cron").CronJob;
    let c = 0, i = 0;

    // redis新增测试
    api.post('/postredis', async (req, res, next) => {
        let redisData = req.body;
        console.log("key:" + redisData.key);
        console.log("value:" + redisData.value);
       // console.log("time:" + redisData.time);
        try {
            let result = await redisUtil.set(redisData.key, redisData.value);
             if(redisData.time==null){
                 console.log("time is null ");
            }else{
                      redisUtil.expire(redisData.key, redisData.time);
                      console.log("time is " + redisData.time);
            }
            res.status(200).json(new Payload(result));
        } catch (error) {
            next(error);
        }
    });

    // redis删除测试
    api.delete('/deleteredis', async (req, res, next) => {
        let key = req.body.key;
        console.log("key:" + key);
        try {
            let result = await redisUtil.del(key);
            // if (result) {
            //     res.status(200).json(new Payload(result));
            // }else{
            //     res.status(200).json(new Payload("不存在该key"));
            // }
            res.status(200).json(new Payload(result));
        } catch (error) {
            next(error);
        }
    });



    return api;
}

